﻿using UnityEngine;
using System.Collections;

public class CameraLerpToTransform : MonoBehaviour {
	public Transform cameraTarget;
	public float trackingSpeed;
	public float minX;
	public float minY;
	public float maxX;
	public float maxY;

	void FixedUpdate() {
		if (cameraTarget == null) return;

		var newPos = Vector2.Lerp (transform.position, cameraTarget.position, Time.deltaTime * trackingSpeed);
		var v3 = new Vector3 (newPos.x, newPos.y, -10.0f);
		var clampX = Mathf.Clamp (v3.x, minX, maxX);
		var clampY = Mathf.Clamp (v3.y, minY, maxY);
		transform.position = new Vector3 (clampX, clampY, v3.z);
	}
}
